Socket
Socket
Sign inDemoInstall

@parcel/watcher

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@parcel/watcher

A native C++ Node module for querying and subscribing to filesystem events. Used by Parcel 2.


Version published
Weekly downloads
3.5M
decreased by-4.97%
Maintainers
1
Weekly downloads
 
Created

What is @parcel/watcher?

The @parcel/watcher package is a file system watcher that provides an efficient way to subscribe to changes in the file system. It is designed to be fast and works across multiple platforms. It can be used to watch for changes in files and directories and perform actions in response to those changes.

What are @parcel/watcher's main functionalities?

Subscribing to file changes

This feature allows you to subscribe to changes in a specific directory. The callback function is called with an array of events whenever a change occurs. Each event contains the type of change (e.g., 'create', 'update', 'delete') and the path to the affected file or directory.

const {subscribe} = require('@parcel/watcher');

async function run() {
  await subscribe('/path/to/directory', (err, events) => {
    if (err) {
      // Handle the error
      return;
    }

    // Handle file system change events
    events.forEach(event => {
      console.log(`Type: ${event.type}, Path: ${event.path}`);
    });
  });
}

run();

Unsubscribing from file changes

This feature allows you to unsubscribe from a previously established subscription. This is useful when you no longer need to watch for changes or when your application is shutting down.

const {subscribe, unsubscribe} = require('@parcel/watcher');

let subscription;

async function run() {
  subscription = await subscribe('/path/to/directory', (err, events) => {
    // Handle file system change events
  });
}

async function stop() {
  await unsubscribe(subscription);
}

run();
// Later on, when you want to stop watching
stop();

Other packages similar to @parcel/watcher

FAQs

Package last updated on 23 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc